//
//  LXMainViewController.swift
//  weibo
//
//  Created by lixin on 16/4/16.
//  Copyright © 2016年 lixin. All rights reserved.
//

import UIKit

class LXMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabbar = LXTabbar()
        
        tabbar.LXDelegate = self
        
        setValue(tabbar, forKey: "tabBar")
        
        addChildViewController(LXHomeViewController(), imgName: "tabbar_home", title: "首页")
        
        addChildViewController(LXMessageViewController(), imgName: "tabbar_message_center", title: "信息")
        
        addChildViewController(LXDiscoverViewController(), imgName: "tabbar_discover", title: "发现")
       
        addChildViewController(LXProfileViewController(), imgName: "tabbar_profile", title: "我的")
    }
    
    func addChildViewController(childController: UIViewController, imgName: String, title: String) {
    
        childController.tabBarItem.image = UIImage(named: imgName)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        
        childController.title = title
        
        addChildViewController(UINavigationController(rootViewController:childController))
    }
}

//MARK: - LXTabbar的代理方法

extension LXMainViewController:LXTabbarDelegate{
    
    func composeBtnClick(){
        
        let composeVc = LXComposeViewController()
        
        presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)
    }
}
